//
//  SearchModel.m
//  ProjectsOne
//
//  Created by iOS开发 on 2018/7/11.
//  Copyright © 2018年 iOS开发. All rights reserved.
//

#import "SearchModel.h"
#import "NSString+Custom.h"

@implementation KeywordModel

- (NSString *)keyword {
    if (!_keyword) {
        NSString *str = @"关键字";
        for (NSInteger i = 0; i < (arc4random() % 3); i++) {
            str = [str stringByAppendingString:@"关键字"];
        }
        _keyword = str;
    }
    return _keyword;
}

- (CGFloat)keywordWidth {
    if (!_keywordWidth) {
        CGFloat textWidth = [self.keyword widthForFont:[UIFont systemFontOfSize:15] height:30] + 26;
        // 防止过长
        if (textWidth >= WIDTH - 30) {
            textWidth = WIDTH - 30;
        }
        _keywordWidth = textWidth;
    }
    return _keywordWidth;
}

@end

@implementation SearchModel

- (NSMutableArray<KeywordModel *> *)searchArr {
    if (!_searchArr) {
        _searchArr = [NSMutableArray array];
        for (NSInteger i = 0; i < (arc4random() % 10) + 1; i++) {
            [_searchArr addObject:[[KeywordModel alloc] init]];
        }
    }
    return _searchArr;
}

@end
